2020-2021 Sunseeker Telemetry and Lighting System
adc12_a_ex6_extendedInputs.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //******************************************************************************
76 //******************************************************************************
77 
78 //Needs to be global in this example
79 //Otherwise, the compiler removes it
80 //because it is not used for anything.
81 volatile uint16_t results[2];
82 
83 void main (void)
84 {
85  //Stop Watchdog Timer
86  WDT_A_hold(WDT_A_BASE);
87 
88  //Initialize the ADC12_A Module
89  /*
90  * Base address of ADC12_A Module
91  * Use internal ADC12_A bit as sample/hold signal to start conversion
92  * USE MODOSC 5MHZ Digital Oscillator as clock source
93  * Use default clock divider of 1
94  */
95  ADC12_A_init(ADC12_A_BASE,
96  ADC12_A_SAMPLEHOLDSOURCE_SC,
97  ADC12_A_CLOCKSOURCE_ADC12OSC,
98  ADC12_A_CLOCKDIVIDER_1);
99 
100  ADC12_A_enable(ADC12_A_BASE);
101 
102  /*
103  * Base address of ADC12_A Module
104  * For memory buffers 0-7 sample/hold for 1024 clock cycles
105  * For memory buffers 8-15 sample/hold for 4 clock cycles (default)
106  * Enable Multiple Sampling
107  */
108  ADC12_A_setupSamplingTimer(ADC12_A_BASE,
109  ADC12_A_CYCLEHOLD_1024_CYCLES,
110  ADC12_A_CYCLEHOLD_4_CYCLES,
111  ADC12_A_MULTIPLESAMPLESENABLE);
112 
113  //Configure Memory Buffers
114  /*
115  * Base address of the ADC12_A Module
116  * Configure memory buffer 0
117  * Map input A8 to memory buffer 0
118  * Vref+ = AVcc
119  * Vref- = AVss
120  * Memory buffer 0 is not the end of a sequence
121  */
122  ADC12_A_configureMemoryParam param0 = {0};
123  param0.memoryBufferControlIndex = ADC12_A_MEMORY_0;
124  param0.inputSourceSelect = ADC12_A_INPUT_A8;
125  param0.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
126  param0.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
127  param0.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
128  ADC12_A_configureMemory(ADC12_A_BASE ,&param0);
129 
130  /*
131  * Base address of the ADC12_A Module
132  * Configure memory buffer 1
133  * Map input A9 to memory buffer 1
134  * Vref+ = AVcc
135  * Vref- = AVss
136  * Memory buffer 1 is not the end of a sequence
137  */
138  ADC12_A_configureMemoryParam param1 = {0};
139  param1.memoryBufferControlIndex = ADC12_A_MEMORY_1;
140  param1.inputSourceSelect = ADC12_A_INPUT_A9;
141  param1.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
142  param1.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
143  param1.endOfSequence = ADC12_A_ENDOFSEQUENCE;
144  ADC12_A_configureMemory(ADC12_A_BASE ,&param1);
145 
146  //Enable memory buffer 1 interrupt
147  ADC12_A_enableInterrupt(ADC12_A_BASE,
148  ADC12IFG1);
149  ADC12_A_enableInterrupt(ADC12_A_BASE,
150  ADC12IE1);
151 
152  while (1)
153  {
154  //Enable/Start sampling and conversion
155  /*
156  * Base address of ADC12_A Module
157  * Start the conversion into memory buffer 0
158  * Use the sequence of channels
159  */
160  ADC12_A_startConversion(ADC12_A_BASE,
161  ADC12_A_MEMORY_0,
162  ADC12_A_SEQOFCHANNELS);
163 
164  //Enter LPM4, Enable interrupts
165  __bis_SR_register(LPM4_bits + GIE);
166  //For debugger
167  __no_operation();
168  }
169 }
170 
171 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
172 #pragma vector=ADC12_VECTOR
173 __interrupt
174 #elif defined(__GNUC__)
175 __attribute__((interrupt(ADC12_VECTOR)))
176 #endif
177 void ADC12ISR (void)
178 {
179  switch (__even_in_range(ADC12IV,34)){
180  case 0: break; //Vector 0: No interrupt
181  case 2: break; //Vector 2: ADC overflow
182  case 4: break; //Vector 4: ADC timing overflow
183  case 6: break; //Vector 6: ADC12IFG0
184  case 8: //Vector 8: ADC12IFG1
185  //Move results, IFG is cleared
186  results[0] =
187  ADC12_A_getResults(ADC12_A_BASE,
188  ADC12_A_MEMORY_0);
189  //Move results, IFG is cleared
190  results[1] =
191  ADC12_A_getResults(ADC12_A_BASE,
192  ADC12_A_MEMORY_1);
193 
194  //Exit active CPU,
195  //SET BREAKPOINT HERE and watch results[]
196  __bic_SR_register_on_exit(LPM4_bits);
197  case 10: break; //Vector 10: ADC12IFG2
198  case 12: break; //Vector 12: ADC12IFG3
199  case 14: break; //Vector 14: ADC12IFG4
200  case 16: break; //Vector 16: ADC12IFG5
201  case 18: break; //Vector 18: ADC12IFG6
202  case 20: break; //Vector 20: ADC12IFG7
203  case 22: break; //Vector 22: ADC12IFG8
204  case 24: break; //Vector 24: ADC12IFG9
205  case 26: break; //Vector 26: ADC12IFG10
206  case 28: break; //Vector 28: ADC12IFG11
207  case 30: break; //Vector 30: ADC12IFG12
208  case 32: break; //Vector 32: ADC12IFG13
209  case 34: break; //Vector 34: ADC12IFG14
210  default: break;
211  }
212 }
213 
void main(void)
volatile uint16_t results[2]
void ADC12ISR(void)
__no_operation()
__bic_SR_register_on_exit(LPM3_bits|GIE)